package main

import (
	"fmt"
	"sync"
)

func printMessage(msg string, wg *sync.WaitGroup) {
	defer wg.Done() // 任务完成后减少计数
	fmt.Println(msg)
}

func main() {
	var wg sync.WaitGroup

	for i := 0; i < 3; i++ {
		wg.Add(1) // 增加等待的 goroutine 数量
		go printMessage(fmt.Sprintf("Goroutine %d", i), &wg)
	}

	wg.Wait() // 等待所有 goroutine 完成
	fmt.Println("All goroutines finished")
}
